package dletc.thread;

import java.util.concurrent.*;

public class TestCallable implements Callable<Integer> {

    //1.实现Callable 重写call()方法 跟run差不多 不过有返回值
    @Override
    public Integer call() throws Exception {
        System.out.println("可调用对象");
        return null;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        
        //2.创建TestCallable对象
        TestCallable t = new TestCallable();
        //3.创建执行服务
        ExecutorService es = Executors.newFixedThreadPool(3);
        //4.提交执行 获得future
        Future submit = es.submit(t);
        //5.获取结果
        Object result = submit.get();
        //6.关闭服务
        es.shutdownNow();

    }
}
